<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/6/24 0024
 * Time: 10:41
 */

namespace app\common\model\mall;


use app\common\model\TimeModel;

class Order extends TimeModel
{
    /**
     * 关联商品
     */
    public function Goods(){
        return $this->belongsTo('app\common\model\mall\Account','goods_id','id')->field('id,title,thumb,image,price');
    }
    /**
     * 关联用户
     */
    public function User(){
        return $this->belongsTo('app\common\model\user\WxUsers','user_id','id')->field('id,nick_name,phone');
    }

    //获取用户订单信息
    public function userInfo(){
        return $this->belongsTo('app\common\model\mall\OrderUserInfo','order_sn','order_sn');
    }
    /**
     * 关联用户信息
     */
    public function OrderUserInfo(){
        return $this->belongsTo('OrderUserInfo','order_sn','order_sn')->field('order_sn,user_name,school,age');
    }

    public static function onAfterInsert($data){

        //$self = new static();
        $article = self::withoutGlobalScope()->find($data->id);

        $article->withoutGlobalScope()->where('id',$data->id)->save(['app_id'=>self::get_appId()]);

    }
}